﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NExplorer
{
	public static class ServiceManager
	{
		private static readonly Dictionary<Type,IService> s_services = new Dictionary<Type, IService>();

		public static T GetService<T>() where T : IService 
		{
			IService service;
			s_services.TryGetValue(typeof(T), out service);
			
			return (T)service;	
		}

		public static void AddService(IService service)
		{
			AddService(service, service.GetType());
		}

		/// <summary>
		/// Adds a service to the service manager.
		/// </summary>
		/// <param name="service">The service to add.</param>
		/// <param name="asType">The type to register the service as. For example, a Foo service might prefer
		/// to be registered as IFoo.</param>
		public static void AddService(IService service, Type asType)
		{
			// TODO: Check for service of existing type, AND check for null
			s_services.Add(asType, service);
		}

		public static IExplorerService Explorer
		{
			get { return GetService<IExplorerService>(); }
		}

		public static IMenuBuilderManager MenuBuilderManager
		{
			get { return GetService<IMenuBuilderManager>(); }
		}

		public static IColumnProviderManager ColumnProviderManager
		{
			get { return GetService<IColumnProviderManager>(); }
		}

		public static IMainToolBar ToolBar
		{
			get { return GetService<IMainToolBar>();  }
		}

		public static FileOperations FileOperations
		{
			get { return GetService<FileOperations>(); }
		}
	}
}
